<template>
	<view>
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput  v-model="dataform.telephone" placeholder="手机号码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput  v-model="dataform.password" placeholder="密码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="login">登录</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataform:{"telephone":"12345678912","password":"123456"}
			}
		},
		methods: {
			login(){
				uni.request({
					url: 'http://localhost:8090/foodapp/user/login',
					method: 'POST',
					data: this.dataform,
					success: res => {
						// 判断是否登录成功
						// 如果是： 1）保存用户信息到本地存储 2)跳转到my页面
						// 否则，提示失败
						if(res.data.success){
							//1）保存用户信息到本地存储 
						/*	uni.setStorage({
								key:"user",
								data:res.data.data,
								success: () => {
									// 2)跳转到my页面
									uni.navigateTo({
										url:'/pages/my/my'
									})
								}
							})
							*/
						   uni.setStorageSync("user",res.data.data)
						   uni.navigateTo({
						   	url:'/pages/my/my'
						   })
							
						}else{
							uni.showToast({
								title: '失败',
								icon: 'none'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>

</style>
